import 'package:flutter/material.dart';

main() {
  runApp(MaterialApp(home: StatelessHome()));
}

class StatelessHome extends StatelessWidget {
  // 与 textField 绑定以获得文本
  var c1 = TextEditingController();

  StatelessHome({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Container'),
          backgroundColor: Colors.red,
        ),
        body: Column(children: [
          const Text(''),
          const Text(''),
          const Text(''),
          TextField(
            controller: c1,
            // obscureText: true, // 隐藏输入内容。输入时有回显
            cursorColor: Colors.purple, // 光标颜色
            cursorWidth: 8, // 光标宽度
            cursorRadius: const Radius.circular(3), // 光标圆角
            maxLines: 3, // 最大行数
            minLines: 1, // 初始行数
            maxLength: 40, // 最多输入字符数量
            decoration: InputDecoration(
              // icon: const Icon(Icons.person), // 输入框外部图标
                prefixIcon: const Icon(Icons.phone), // 输入框中左边图标
                // suffixIcon: Icon(Icons.cancel), // 输入框中右边图标
                suffixIcon: IconButton(onPressed: () { c1.clear(); }, icon: Icon(Icons.cancel)),
                hintText: '请输入账号/手机/邮箱',
                labelText: '文本框名',
                // border: const OutlineInputBorder(), //方形框框
                border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))
            ),
          ),
          ElevatedButton(
              onPressed: () {
                print(c1.text);
              },
              child: const Text('获取文本'))
        ]));
  }
}